package avicit.im.lantop.basic.useconfig.rest;


import avicit.im.lantop.basic.companycorrespondence.rest.CompanyCorrespondenceServiceRest;
import avicit.im.lantop.basic.useconfig.service.UseConfigService;
import avicit.im.lantop.basic.useconfig.service.api.UseConfigServiceApi;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "UseConfigServiceService", description = "UseConfigServiceService")
@RequestMapping("/api/avicit/im/lantop/basic/useconfig/rest/UseConfigServiceRest")
public class UseConfigServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(UseConfigServiceRest.class);


    @Autowired(required = true)
    private UseConfigService useConfigService;


    /**
     * 初始化系统业务参数配置信息
     * @param map
     * @return
     */
    @PostMapping("/selectUserConfig")
    @ApiOperation(value = "初始化系统业务参数配置信息")
    public ResponseMsg<List<Map<String, Object>>> selectUserConfig(@ApiParam(value = "初始化系统业务参数配置信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String sysId = (String) map.get("sysId");
            String deptId = (String) map.get("deptId");
            String orgId = (String) map.get("orgId");
            List<Map<String, Object>> maps = useConfigService.selectUserConfig(sysId, deptId, orgId);
            responseMsg.setResponseBody(maps);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取配置的数据
     * @param map
     * @return
     */
    @PostMapping("/findConfig")
    @ApiOperation(value = "获取配置的数据")
    public ResponseMsg<Map<String, String>> findConfig(@ApiParam(value = "获取配置的数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Map<String, String>> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String orgId1 = (String) map.get("orgId1");
            Map<String, String> config = useConfigService.findConfig(orgId, orgId1);
            responseMsg.setResponseBody(config);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除本全宗下配置数据信息
     * @param map
     * @return
     */
    @PostMapping("/deleteUseData")
    @ApiOperation(value = "删除本全宗下配置数据信息")
    public ResponseMsg deleteUseData(@ApiParam(value = "删除本全宗下配置数据信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String sysId = (String) map.get("sysId");
            String deptId = (String) map.get("deptId");
            String orgId = (String) map.get("orgId");
            useConfigService.deleteUseData(sysId,deptId,orgId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 新增利用配置数据信息
     * @param map
     * @return
     */
    @PostMapping("/createArchivalMessage")
    @ApiOperation(value = "新增利用配置数据信息")
    public ResponseMsg createArchivalMessage(@ApiParam(value = "新增利用配置数据信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String sysId = (String) map.get("sysId");
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String useType = (String) map.get("useType");
            String o = (String) map.get("o");
            String o1 = (String) map.get("o1");
            String o2 = (String) map.get("o2");
            String appointmentArsDays = (String) map.get("appointmentArsDays");
            useConfigService.createArchivalMessage(sysId, orgId, deptId, useType, o, o1, o2, appointmentArsDays);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
